<?php
namespace  app\admin\model;

use think\Exception;
use think\facade\Db;
use think\facade\Request;
use think\Model;
//品牌页
class Brand extends Model{
    //定义表主键
    protected $pk = 'brand_id';
    //品牌列表查询
    public static function   brandList($where,$whereOr,$data){
        $brand=Brand::where($where)
            ->where(function ($query) use($whereOr){
                $query->whereOr($whereOr);
            })
            ->order("sort_order")->paginate([
                'list_rows'=> 5,
                'query'=>$data
            ]);
        return $brand;
    }
     public static function   getIfShowImgAttr($v,$data){
        if ($data['if_show']==1){
            return '<font color="#00CC99">是</font>';
        }else{
            return '<font color="#CE3E3E">否</font>';
        }
    }
    public static function   getRecommendedImgAttr($v,$data){
        if ($data['recommended']==1){
            return '<font color="#00CC99">是</font>';
        }else{
            return '<font color="#CE3E3E">否</font>';
        }
    }
    public static function   getBrandLogoImgAttr($v,$data){
        if ($data['brand_logo']!=NULL){
            return "<img src='/static/{$data["brand_logo"]}' width='70' height='50'/>";
        }else{
            return  "<img src='/static/images/default.png' alt='' width='70' height='50' />";
        }
    }
      //品牌添加
     public static function   getBrandAdd($data){
        try{
            $res=Brand::strict(true)->insert($data);

        }catch (Exception $e){
            $res=false;
        }
        return $res;
         }

         //品牌修改
     public static function   getBrandEdit($get,$data){
        if (Request::isPost()){
            try{
                $res=Brand::update($data);
            }catch (Exception $e){
                $res=false;
            }
            return $res;


        }else{
            $find=Brand::strict(true)->where('brand_id',$get['id'])->find()->toArray();
            return $find;
        }

         }




}